package com.csap.framework.oauth2.client.user.strategy;

import cn.dev33.satoken.LoginUtil;
import com.csap.framework.oauth2.FindUserService;
import com.csap.framework.oauth2.UserInfo;
import com.csap.framework.oauth2.UserInfoMod;
import com.csap.framework.oauth2.client.Oauth2ClientProperties;
import com.csap.framework.oauth2.client.rest.Oauth2ClientApi;
import lombok.AllArgsConstructor;

/**
 * http模式获取用户信息
 *
 * @author yangchengfu
 * @dataTime 2021年-05月-16日 16:04:00
 **/
@AllArgsConstructor
public class FeignFindUserServiceImpl implements FindUserService {
    private final Oauth2ClientApi oauth2ClientApi;
    private final Oauth2ClientProperties oauth2ClientProperties;

    @Override
    public UserInfoMod mod() {
        return UserInfoMod.FEIGN;
    }

    @Override
    public UserInfo findByUserId(Object loginId) {
        return findByUserId(loginId, LoginUtil.loginType());
    }

    @Override
    public UserInfo findByUserId() {
        return oauth2ClientApi.getUserinfo().getData();
    }

    @Override
    public UserInfo findByUserId(Object loginId, String loginType) {
        return oauth2ClientApi.userInfoId(loginId.toString()).getData();
    }
}
